{extend name="public:base"/}
{block name="header"}
<style>
    .form input{
        width:300px;
        padding:5px;
    }
    .form input:focus{
        border:1px solid #ff0000;
    }
    .signup_now{
        padding:5px 20px;
        background-color: #0b6fa2;
        color:#fff;
        border-bottom:3px solid #0b6fa2;
    }
    .signup_now a{
        color:#fff;
    }
    .signup_other{
        border-bottom:3px solid #0b6fa2;
        padding:5px 20px;
    }
</style>
{/block}
{block name="main"}
    <div class="ShareAnyContainer" style="font-size: 14px;">
        当前位置：<a href="/" title="首页">首页</a>&nbsp;&nbsp;/&nbsp;&nbsp;<a
            href="{:url('shop/login/register')}" title="注册">注册</a>
    </div>
    <div class="ShareAnySeparate"></div>
    <div class="ShareAnyContainer">
        <div class="line"></div>
    </div>
    <div class="ShareAnySeparate"></div>
    <div class="ShareAnyContainer form" style="line-height: 50px; text-align: center;">
        <p><span class="signup_other">
                <a href="{:url('shop/login/register')}" title="手机注册">手机注册</a>
           </span>
           <span class="signup_now">
                <a href="{:url('shop/login/registerEmail')}" title="邮箱注册">邮箱注册</a>
           </span>
        </p>
        <p>电子邮件：<input type="text" id="email"></p>

        <p>
            <button id="getcode" style="padding:10px 81px;">获取验证码</button>
        </p>
        <p>登录密码：<input type="password" id="password"></p>

        <p>确认密码：<input type="password" id="repassword"></p>

        <p>验证码：&nbsp;&nbsp;&nbsp;<input type="text" id="code"></p>
        <p>
            <button id="submit" style="padding:10px 25px;">同意网站会员注册协议并注册</button>
            <br><a target="_blank" href="/account/readme/" title="网站会员注册协议">网站会员注册协议</a></p>
    </div>
{/block}
{block name="footer"}
<script type="text/javascript">
    $(function (argument) {
            var email = '';
            var regEmail = /.+@.+\.[a-zA-Z]{2,4}$/;
            $('#getcode').click(function(){
                email=$("#email").val();
                var code = $('#code').val();

                if(!regEmail.test(email)){
                    alert('邮箱输入有误');
                    return false;
                }else{
                    //发送邮箱验证码
                    $.get("{:url('shop/login/sendEmailCode')}", {email:email}, function(event){
                            console.log(event);
                    });
                }
            });

            $('#submit').click(function(){
                var code = $('#code').val();
                var password = $('#password').val();
                var repassword = $('#repassword').val();
                if(!regEmail.test(email)){
                    alert('邮箱输入有误');return false;
                }else if(code == ''){
                    alert('验证码不能为空');return false;
                }else if(password != repassword || password == ''){
                    alert('两次密码输入不一致');return false;
                }

                if(code != ''){
                    $.post("{:url('shop/login/getEmailCode')}",{email:email, code:code},function(res){
                            if(res.code != '0'){
                                alert(res.msg);return false;
                            }else{
                                //验证成功 提交注册
                                $.post("{:url('shop/login/registerEmail')}", {email:email, code:code, password:password}, function(obj){
                                        if(obj.code == 0){
                                            alert(obj.msg);
                                            window.location.href = "{:url('shop/login/index')}";
                                        }else{
                                            alert(obj.msg);
                                        }
                                },'json')
                            }
                    })
                }
        });
    });
</script>
{/block}